package org.fireflow2.designer.eclipse.modelwrapper.basic;

import org.eclipse.draw2d.geometry.Dimension;
import org.fireflow.pdl.fpdl20.diagram.DiagramElement;
import org.fireflow.pdl.fpdl20.diagram.Fpdl20DiagramElement;
import org.fireflow.pdl.fpdl20.diagram.RouterShape;
import org.fireflow.pdl.fpdl20.diagram.basic.Rectangle;
import org.fireflow.pdl.fpdl20.process.Synchronizer;
import org.fireflow2.designer.eclipse.figures.StartNodeFigure;
import org.fireflow2.designer.eclipse.modelwrapper.NodeWrapper;
import org.fireflow2.designer.eclipse.modelwrapper.SubProcessWrapper;
import org.fireflow2.designer.eclipse.util.Util4Eclipse;

public class RouterWrapper extends NodeWrapper {
	public RouterWrapper(SubProcessWrapper subflowWrapper, Synchronizer arg0,
			DiagramElement arg1) {
		super(subflowWrapper, arg0, arg1);
	}

	public String getElementType() {
		return Fpdl20DiagramElement.ROUTER.name();
	}

	public org.eclipse.draw2d.geometry.Rectangle calculateBounds() {
		String displayName = this.getDisplayName();
		// 计算bounds
		RouterShape routerShape = (RouterShape) this.getDiagramElement();
		Rectangle fireRect = (Rectangle) routerShape.getShape();

		Dimension dimension = Util4Eclipse.getTextSize(
				fireRect.getTitleLabel(), displayName);

		org.eclipse.draw2d.geometry.Rectangle rectangle = this.getBox();
		if (dimension.width > 0) {
			rectangle.height += StartNodeFigure.IconTextGap;
			rectangle.height += dimension.height;// 字体高度
			if (dimension.width > rectangle.width) {
				int oldWidth = rectangle.width;
				rectangle.width = dimension.width;
				rectangle.x -= ((dimension.width - oldWidth) / 2);
			}
		}
		return rectangle;
	}
}
